#ifndef KC__MYSQLCONNECTOR__H_KC
#define KC__MYSQLCONNECTOR__H_KC

#include <string>
#include <unistd.h>
#include <mysql/mysql.h>
#include "DatabaseTable.h"

namespace kc_sf
{
	class MySQLConnector
	{
		public:

			MySQLConnector();
			~MySQLConnector();

			DatabaseRecord readTableColumnNames( const std::string &table_name ) const;
			DatabaseTable readTable( const std::string &table_name ) const;
			DatabaseTable query( const std::string &query_str ) const;
			void queryWithoutResult( const std::string &query_str ) const;
			size_t insertInto( const std::string &table_name, const DatabaseRecord &column_names,
				const DatabaseRecord &record ) const;

		private:

			MYSQL *m_connection;

			std::string readMySQLError() const;
	};
}

#endif // KC__MYSQLCONNECTOR__H_KC

/*
	std::string table_name = "archive_email";
	MySQLConnector connector;
	DatabaseRecord column_names = connector.readTableColumnNames( table_name );

	std::cout << "Tabela archive_email posiada kolumny: " << std::endl;
	foreach( std::string column_name, column_names )
	{
		std::cout << column_name << " ";
	}

	DatabaseRecord selected_column_names;
	std::cout << std::endl << "Wpisz kolumny które chcesz uzupelnic np. kol1, kol2 i wcisnij <enter> " << std::endl;
	std::string selected;
	std::getline( std::cin, selected );
	selected.erase( std::remove( selected.begin(), selected.end(), ' '), selected.end() );
	boost::split( selected_column_names, selected, boost::is_any_of( "," ) );

	DatabaseRecord values;
	std::cout << "Wpisz wartosci które chcesz wstawic np. value1, value2 i wcisnij <enter> " << std::endl;
	selected.clear();
	std::getline( std::cin, selected );
	selected.erase( std::remove( selected.begin(), selected.end(), ' '), selected.end() );
	boost::split( values, selected, boost::is_any_of( "," ) );

	connector.insertInto( table_name, selected_column_names, values );

	DatabaseTable archive_email_table = connector.readTable( table_name );
	DatabaseRecords records = archive_email_table.selectAll();

	foreach( std::string column_name, column_names )
	{
		std::cout << column_name << " ";
	}
	std::cout << std::endl;

	foreach( DatabaseRecord record, records )
	{
		foreach( std::string column, record )
		{
			std::cout << column << " ";
		}
		std::cout << std::endl;
	}
 */
